package org.coopac.dao.impl;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

public abstract class BaseDaoImpl<T> {
	 
	
	protected abstract SessionFactory getSessionFactory();
	
	@SuppressWarnings("unchecked")
	public List<T> listar(Class<T> klass){
		Session session = getSessionFactory().getCurrentSession();
		return session.createCriteria(klass).list();
	}
	
	public void save(Object o){
		getSessionFactory().getCurrentSession().save(o);
	}
	
	public void update(Object o){
		getSessionFactory().getCurrentSession().update(o);
	}
	
	public void delete(Object o){
		getSessionFactory().getCurrentSession().delete(o);
	}
	
	public Object getById(Class<T> klass, Integer id){
		return getSessionFactory().getCurrentSession().get(klass, id);
	}
	
}
